﻿Imports System
Imports System.Collections
Imports System.Configuration
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.Page
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.EnterpriseServices
Imports System.Xml
Imports Comunes
Public Class cls_sesion_ajax
    Inherits System.Web.UI.Page
#Region "VARIABLES"
    Protected _SESE_NID As String
    Protected _USUS_NID As Integer
    Protected _USUS_USUARIO As String
    Protected _PEPE_NID As Integer
    Protected _SESE_FECHA_ACCESO As String

    Public ds As New DataSet
    Dim DataTable As New DataTable
    Dim RespuestaJson As New clsJsonSR.clsJsonSR()
    Dim obj_error As New cls_errores()
    Public objWS As New Service.Service
    Public Param As New Parametros()
    Public objLib As New clsLibreria()
    Public StrKeyConn As String = System.Configuration.ConfigurationManager.AppSettings.Get("KeyConexion")
    Public GlsError As String = "", SrcError As String = "", WsError As String = "", MetError As String = "", NumError As String = ""
#End Region
#Region "PROPERTY"
    Property SESE_NID() As String
        Get
            Return _SESE_NID
        End Get
        Set(ByVal value As String)
            _SESE_NID = value
        End Set
    End Property
    Property USUS_NID() As Integer
        Get
            Return _USUS_NID
        End Get
        Set(ByVal value As Integer)
            _USUS_NID = value
        End Set
    End Property
    Property USUS_USUARIO() As String
        Get
            Return _USUS_USUARIO
        End Get
        Set(ByVal value As String)
            _USUS_USUARIO = value
        End Set
    End Property
    Property PEPE_NID() As String
        Get
            Return _PEPE_NID
        End Get
        Set(ByVal value As String)
            _PEPE_NID = value
        End Set
    End Property
    Property SESE_FECHA_ACCESO() As String
        Get
            Return _SESE_FECHA_ACCESO
        End Get
        Set(ByVal value As String)
            _SESE_FECHA_ACCESO = value
        End Set
    End Property
#End Region
#Region "CONSTRUCTOR"
    Sub New()
        _SESE_NID = ""
        _USUS_NID = 0
        _USUS_USUARIO = ""
        _PEPE_NID = 0
        _SESE_FECHA_ACCESO = ""
    End Sub
#End Region
#Region "FUNCIONES Y PROCEDIMIENTOS"
    Public Overloads Sub onload(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles MyBase.Load        
        Try
            If Session("SESE_NID") Is Nothing Then
                obj_error.id = -830203
                obj_error.desc = "Su sesión ha caducado. Vuelva a iniciar sesión."
                Response.Write(RespuestaJson.listaParaGrilla(False, 0, DataTable, obj_error))
            Else
                Param.Limpiar()
                Param.Agregar("SESE_NID", Session("SESE_NID"))
                ds = objWS.EjecutarConParametroXML(StrKeyConn, Param.GeneraDocXML("parametros"), "SPBS_SESE_OBTENER_SESION_USUARIO")
                If objLib.RevisaErrores(ds, GlsError, SrcError, WsError, MetError, NumError) = "0" Then
                    If ds.Tables(0).Rows(0).Item("ErrorNumber").ToString = "1" Then
                        With ds.Tables(0).Rows(0)
                            SESE_NID = .Item("SESE_NID").ToString
                            USUS_NID = .Item("USUS_NID").ToString
                            USUS_USUARIO = .Item("USUS_USUARIO").ToString
                            PEPE_NID = .Item("PEPE_NID").ToString
                            SESE_FECHA_ACCESO = .Item("SESE_FECHA_ACCESO").ToString
                            Session("USUS_NOMBRECOMPLETO") = .Item("USUS_NOMBRECOMPLETO").ToString
                        End With
                    ElseIf ds.Tables(0).Rows(0).Item("ErrorNumber").ToString = "0" Then
                        obj_error.id = -830203
                        obj_error.desc = ds.Tables(0).Rows(0).Item("ErrorMessage").ToString
                        Response.Write(RespuestaJson.listaParaGrilla(False, 0, ds.Tables(0), obj_error))
                        Return
                    End If
                End If
            End If
        Catch ex As Exception
            obj_error.id = -830203
            obj_error.desc = "Su sesión ha caducado. Vuelva a iniciar sesión."
            Response.Write(RespuestaJson.listaParaGrilla(False, 0, DataTable, obj_error))
            Return
        Finally
            ds.Dispose()
            ds = Nothing
        End Try
    End Sub
#End Region
End Class
